#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {
    auto helper = [](uint64_t p, uint64_t n) {
        vector<unsigned> v;
        while (p) {
            v.push_back(p % 10);
            p /= 10;
        }
        return accumulate(v.begin(), v.end(), 0ULL) == n;
    };

    vector<uint64_t> v;
    for (uint64_t n = 2; ; ++n) {
        uint64_t prod = 1;
        uint64_t limit = static_cast<uint64_t>(log(UINT64_MAX) / log(n));
        for (uint64_t i = 0; i < limit; ++i) {
            prod *= n;
            if (prod > 9 && helper(prod, n))
                v.push_back(prod);
        }
        if (v.size() > 30)
            break;
    }
    cout << v[29] << endl;
}   // 248155780267521